<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="/include/taglibs.jsp" %>
<html>
<head>
    <%@include file="/include/header.html" %>
    <script type="text/javascript" src="${ctx}/appjs/ticket/detailTenantTicketType.js"></script>
    <style>
        .seach-box {
            height: 200px;
            border: 1px solid #eee;
            padding-left: 15px;
            padding-top: 10px;
            margin-top: 10px;
        }

        .layui-tree {
            pointer-events: none;
        }

        .connectivity_inner_seach, .connectivity_seach {
            padding-left: 0;
            padding-top: 0px;
            overflow: auto;
        }

        .seach-box ul {
            height: 100%;
            width: 100%;
            overflow: auto;
        }

        .seach-box ul li {
            padding-top: 3px;
            display: flex;
        }

        .layui-form-checkbox i {
            height: 30px;
        }

        .layui-checkbox-disbaled span {
            background-color: #5FB878 !important;
        }

        .hide {
            display: none !important;
        }

        .notClick {
            pointer-events: none;
        }
    </style>
</head>

<script type="text/javascript">
    $('#topLink', window.parent.document).html(function (i, origText) {
        return '<ol class="breadcrumb">' +
            '<li class="breadcrumb-item">' +
            '<a href="">主页</a>' +
            '</li>' +
            '<li class="breadcrumb-item">' +
            '<a>运营管理</a>' +
            '</li>' +
            '<li class="breadcrumb-item">' +
            '<strong>优惠券详情</strong>' +
            '</li>' +
            '<li class="breadcrumb-item">' +
            '<a href="javascript:window.history.back()"><i class="fa fa-times"></i> 返回</a>' +
            '</li>' +
            '</ol>';
    });

</script>

<body class="gray-bg">
<div class="wrapper wrapper-content ">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <div class="columns pull-left">
                        <h5 class="font-bold">优惠券详情</h5>
                    </div>
                    <div class="ibox-tools">
                        <a class="close-link">
                            <i class="fa fa-times"></i>
                        </a>
                    </div>
                </div>

                <div class="ibox-content">
                    <form class="form-horizontal m-t layui-form" id="frmTenantTicketType">
                        <input type="hidden" name="ticketTypeId" id="ticketTypeId"
                               value="${tenantTicketType.ticketTypeId}">
                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">卡券名称：</label>
                            <div class="col-sm-4">
                                <input type="text" class="form-control" id="ticketName" readonly
                                       value="${tenantTicketType.ticketName}" name="ticketName">
                            </div>
                        </div>
                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">卡劵类型：</label>
                            <div class="col-sm-4">
                                <select class="form-control" name="ticketSuitType" readonly="true" id="ticketSuitType" disabled>
                                    <c:if test="${tenantTicketType.ticketSuitType == '0'}">
                                        <option value="0" selected>充电减免</option>
                                    </c:if>
                                    <c:if test="${tenantTicketType.ticketSuitType == '1'}">
                                        <option value="1" selected>服务费减免</option>
                                    </c:if>
                                    <c:if test="${tenantTicketType.ticketSuitType == '2'}">
                                        <option value="2" selected>充电满折</option>
                                    </c:if>
                                    <c:if test="${tenantTicketType.ticketSuitType == '3'}">
                                        <option value="3" selected>服务费满折</option>
                                    </c:if>
                                    <c:if test="${tenantTicketType.ticketSuitType == '4'}">
                                        <option value="4" selected>代金券</option>
                                    </c:if>
                                </select>
                            </div>
                        </div>

                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">发放方式：</label>
                            <div class="col-sm-1">
                                <input type="radio" class="form-control" name="ticketSource" lay-filter="ticketSource" value="0" title="系统发放" checked disabled>
                            </div>
                            <div class="col-sm-1">
                                <input type="radio" class="form-control" name="ticketSource" lay-filter="ticketSource" value="1" title="主动领取" disabled <c:if test="${tenantTicketType.ticketSource == '1'}">checked</c:if>>
                            </div>
                        </div>
                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">发放时间：</label>
                            <div class="col-sm-4">
                                <input type="text" class="form-control" id="sendDate" name="sendDate" value="<fmt:formatDate value="${tenantTicketType.sendDate}" pattern="yyyy-MM-dd" />" readonly>
                            </div>
                        </div>

                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">使用条件(满减多少可用)：</label>
                            <div class="col-sm-4">
                                <input type="text" class="form-control" id="useRequireAmount" readonly
                                       value="${tenantTicketType.useRequireAmount}" name="useRequireAmount">
                            </div>
                            <div class="col-sm-2 layui-form-mid layui-word-aux">元</div>
                        </div>
                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">有效期：</label>
                            <div class="col-sm-1">
                                <input type="radio" class="form-control"
                                       readonly ${tenantTicketType.effectType=="0"?"checked":"disabled"}
                                       name="effectType"
                                       lay-filter="effectType" title="获取后" value="0">
                            </div>
                            <div class="col-sm-1">
                                <input type="radio" class="form-control"
                                       readonly ${tenantTicketType.effectType=="1"?"checked":"disabled"}
                                       name="effectType"
                                       lay-filter="effectType"
                                       title="在日期" value="1">
                            </div>
                        </div>
                        <div class="form-group row gainDiv ${tenantTicketType.effectType=="0"?"":"hide"}">
                            <label class="col-sm-3 col-form-label text-right"></label>
                            <div class="col-sm-1">
                                <input type="checkbox" checked disabled title="获取后">
                            </div>
                            <div class="col-sm-2"><input type="text" class="form-control" readonly
                                                         value="${tenantTicketType.effectDay}" id="effectDay"
                                                         name="effectDay">
                            </div>
                            <div class="col-sm-2 layui-form-mid layui-word-aux">天内有效(空为不限制时间用时)</div>
                        </div>
                        <div class="form-group row dateDiv ${tenantTicketType.effectType=="1"?"":"hide"}">
                            <label class="col-sm-3 col-form-label text-right"></label>
                            <div class="col-sm-1">
                                <input type="checkbox" checked disabled title="在日期">
                            </div>
                            <div class="col-sm-2"><input id="effectStartDate" name="effectStartDate" type="text"
                                                         value="<fmt:formatDate value="${tenantTicketType.effectStartDate}" pattern="yyyy-MM-dd" />"
                                                         disabled
                                                         class="form-control"
                                                         placeholder="开始时间"></div>
                            <div class=" layui-form-mid layui-word-aux " style="text-align: center;margin-right: 0">-
                            </div>
                            <div class="col-sm-2"><input id="effectEndDate" name="effectEndDate" type="text"
                                                         value="<fmt:formatDate value="${tenantTicketType.effectEndDate}" pattern="yyyy-MM-dd" />"
                                                         disabled
                                                         class="form-control"
                                                         placeholder="结束时间"></div>
                            <div class="col-sm-3 layui-form-mid layui-word-aux">日期范围内有效(空为不限制时间用时)</div>
                        </div>
                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">优惠方式：</label>
                            <div class="col-sm-1">
                                <input type="radio" class="form-control"
                                       readonly ${tenantTicketType.discountType=="0"?"checked":"disabled"}
                                       name="discountType"
                                       lay-filter="discountType" value="0" title="立减">
                            </div>
                            <div class="col-sm-2">
                                <input type="radio" class="form-control"
                                       readonly ${tenantTicketType.discountType=="1"?"checked":"disabled"}
                                       name="discountType" lay-filter="discountType"
                                       value="1" title="打折">
                            </div>
                        </div>
                        <div class="form-group row reductionDiv ${tenantTicketType.discountType=="0"?"":"hide"}">
                            <label class="col-sm-3 col-form-label text-right"></label>
                            <div class="col-sm-1">
                                <input type="checkbox" checked disabled title="立减">
                            </div>
                            <div class="col-sm-2">
                                <input type="text" class="form-control" readonly
                                       value="${tenantTicketType.discountAmount}" name="discountAmount">
                            </div>
                            <div class="col-sm-1 layui-form-mid layui-word-aux">元</div>
                        </div>
                        <div class="form-group row discountDiv ${tenantTicketType.discountType=="1"?"":"hide"}">
                            <label class="col-sm-3 col-form-label text-right"></label>
                            <div class="col-sm-1">
                                <input type="checkbox" checked disabled title="打折">
                            </div>
                            <div class="col-sm-2">
                                <input type="text" class="form-control" readonly value="${tenantTicketType.discount}"
                                       name="discount">
                            </div>
                            <div class="col-sm-1 layui-form-mid layui-word-aux">折(0~1)</div>
                        </div>

                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">发放总数：</label>
                            <div class="col-sm-4">
                                <input type="text" class="form-control" id="totalTicket" readonly
                                       value="${tenantTicketType.totalTicket}" name="totalTicket">
                            </div>
<%--                            <input type="checkbox" name="isMax" id="isMax" title="无限制" value="1"--%>
<%--                                   lay-filter="isMax"  ${tenantTicketType.isMax=="1"?"checked":""} disabled >--%>
                            <div class="col-sm-3">
                                <p class="couponTips layui-word-aux">*优惠券的总数,用完该优惠券不能继续发放.</p>
                            </div>
                        </div>

                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">领取次数：</label>
                            <div class="col-sm-4">
                                <input type="text" class="form-control" id="ticketUnitCount" name="ticketUnitCount" value="${tenantTicketType.ticketUnitCount}" readonly>
                            </div>
                        </div>

                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">用户类型：</label>
                            <div class="col-sm-4">
                                <select class="form-control" name="applianceUser" id="applianceUser" disabled>
                                    <option value="0" <c:if test="${tenantTicketType.applianceUser == '0'}">selected</c:if>>全部用户</option>
                                    <option value="1" <c:if test="${tenantTicketType.applianceUser == '1'}">selected</c:if>>新用户</option>
                                    <option value="9" <c:if test="${tenantTicketType.ticketSource == '9'}">selected</c:if>>等级会员</option>
                                    <option value="10" <c:if test="${tenantTicketType.applianceUser == '10'}">selected</c:if>>企业用户</option>
                                </select>
                            </div>
                        </div>

                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">会员等级：</label>
                            <div class="col-sm-4">
                                <select class="form-control" name="applicnceLevel" id="applicnceLevel" disabled>
                                    <option value="${tenantTicketType.applicnceLevel}">${tenantTicketType.applicnceLevel}</option>
                                </select>
                            </div>
                        </div>

                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">与其他优惠折扣不能同时使用：</label>
                            <div class="layui-input-block">
                                <input type="checkbox" id="ticketExclusivity" class="form-control" lay-skin="switch" disabled
                                       <c:if test="${tenantTicketType.ticketExclusivity == '1'}">checked</c:if>
                                        value="${tenantTicketType.ticketExclusivity}"
                                       name="ticketExclusivity" lay-text="启用|禁用" lay-filter="ticketExclusivity">
                            </div>
                        </div>

                        <div class="form-group row" style="align-items: baseline">
                            <label class="col-sm-3 col-form-label text-right">站点限制：</label>
                            <div class="col-sm-6 layui-form-mid layui-word-aux">*勾选对应站点，才能在对应的站点进行使用</div>
                        </div>
                        <div class="form-group row" style="align-items: baseline">
                            <div class="col-sm-3"></div>
                            <div class="col-sm-2 " style="margin-top: 10px">
                                <div class="checkallbox">
                                    <input lay-skin="primary" type="checkbox" disabled id="self_checkall" name="type"
                                           lay-filter="self_allChoose" value="checkall"/><span>站点</span></div>
                                <div class="seach-box self_seach">
                                    <ul></ul>
                                </div>
                            </div>
                        </div>


                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">卡劵说明：</label>
                            <div class="col-sm-4">
                                <textarea class="form-control" id="remark" name="remark" readonly>${tenantTicketType.remark}</textarea>
                            </div>
                        </div>

                        <%--<div class="form-group">--%>
                        <%--<div class="col-sm-3 col-sm-offset-8 text-right">--%>
                        <%--&lt;%&ndash;<button type="button" class="btn btn-primary" onclick="addTenantTicketType.init()">提交</button>&ndash;%&gt;--%>
                        <%--<button type="submit" class="btn btn-primary">提交</button>--%>
                        <%--</div>--%>
                        <%--</div>--%>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    addTenantTicketType.init();
</script>
</body>
</html>
<script>

    $(function () {
        var isMax = $("[name='isMax']").is(":checked")
        if (isMax) {
            $('#totalTicket').val("")
        }
    })

    //获取自营/非自营/互联互通外部桩群
    function listTicketStation() {
        $.ajax({
            cache: false,
            type: "POST",
            url: prefix + "/listTicketStation",
            data: {
                "ticketTypeId": $("#ticketTypeId").val()
            },
            // processData: false,
            // contentType: false,
            async: false,
            error: function (request) {
                parent.layer.alert("Connection error");
            },
            success: function (data) {
                console.log(data)
                var str1 = '';
                var str2 = '';
                var str3 = '';
                var str4 = '';
                var self_selectedList = 0;
                var unSelf__selectedList = 0;
                var connectivity_selectedList = 0;
                for (var i = 0; i < data.data.length; i++) {
                    if (data.data[i].hlhtOperatorId == null) {//是否互联互通内部桩群，0是，null不是
                        if (data.data[i].bizType == "0") {//0自营
                            str1 += `<li><input lay-skin="primary" type="checkbox" class="elecStationId" lay-filter="self_list" disabled \${data.data[i].select=="0"?"checked":""}  value="\${data.data[i].elecStationId}"/><span>\${data.data[i].stationName}</span></li>`
                        } else if (data.data[i].bizType == "1") {//1非自营
                            str2 += ` <li><input lay-skin="primary" type="checkbox" class="elecStationId" lay-filter="unSelf_list" disabled \${data.data[i].select=="0"?"checked":""} value="\${data.data[i].elecStationId}"/><span>\${data.data[i].stationName}</span></li>`
                        }
                    }
                    // else {//互联互通外部
                    //     str3 += `<li><input lay-skin="primary" type="checkbox" class="elecStationId" lay-filter="connectivity_list" disabled \${data.data[i].select=="0"?"checked":""} value="\${data.data[i].elecStationId}"/><span>\${data.data[i].stationName}</span></li>`
                    // }
                }
                $(".self_seach ul").append(str1);
                $(".unSelf_seach ul").append(str2);
                // $(".connectivity_seach ul").append(str3);
                if ($(".self_seach input[type='checkbox']").length > 0 && ($(".self_seach input[type='checkbox']:checked").length == $(".self_seach input[type='checkbox']").length)) {
                    $("#self_checkall").prop("checked", true).attr("disabled", "disabled");
                }
                if ($(".unSelf_seach input[type='checkbox']").length > 0 && ($(".unSelf_seach input[type='checkbox']:checked").length == $(".unSelf_seach input[type='checkbox']").length)) {
                    $("#unSelf_checkall").prop("checked", true).attr("disabled", "disabled");
                }
                // if($(".connectivity_seach input[type='checkbox']").length>0 && ($(".connectivity_seach input[type='checkbox']:checked").length == $(".connectivity_seach input[type='checkbox']").length)){
                //     $("#connectivity_checkall").prop("checked",true).attr("disabled","disabled");
                // }
            }
        });
    }

    listTicketStation()


</script>
